package com.jbit.hxy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jbit.hxy.common.Result;
import com.jbit.hxy.mapper.WxOrderDetailMapper;
import com.jbit.hxy.mapper.WxOrderMapper;
import com.jbit.hxy.model.dto.WxOrderDetailsDTO;
import com.jbit.hxy.model.po.WxOrder;
import com.jbit.hxy.model.vo.OrderVO;
import com.jbit.hxy.service.order.WxOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 28575
* @description 针对表【wx_order(订单表)】的数据库操作Service实现
* @createDate 2024-09-13 14:28:18
*/
@Service
@RequiredArgsConstructor
public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder>
    implements WxOrderService {
    private final WxOrderMapper wxOrderMapper;
    private final WxOrderDetailMapper wxOrderDetailMapper;


    @Override
    public List<OrderVO> getOrderByOpenidAndStatus(String openid, Integer status) {
        if (status == 0){
            List<WxOrder> wxOrders = wxOrderMapper.getOrderByOpenid(openid);
            ArrayList<OrderVO> orderVOS = new ArrayList<>();
            for (WxOrder wxOrder : wxOrders) {
                OrderVO orderVO = new OrderVO();
                BeanUtils.copyProperties(wxOrder,orderVO);
                List<WxOrderDetailsDTO> wxOrderDetailsDTOS = wxOrderDetailMapper.getWxOrderDetailsByOrderId(wxOrder.getId());
                orderVO.setOrderDetails(wxOrderDetailsDTOS);
                orderVOS.add(orderVO);
            }
            return orderVOS;
        }
        List<WxOrder> wxOrders = wxOrderMapper.getOrderByOpenid(openid);
        ArrayList<OrderVO> orderVOS = new ArrayList<>();
        for (WxOrder wxOrder : wxOrders) {
            OrderVO orderVO = new OrderVO();
            if (wxOrder.getStatus() == status) {
                BeanUtils.copyProperties(wxOrder,orderVO);
                List<WxOrderDetailsDTO> wxOrderDetailsDTOS = wxOrderDetailMapper.getWxOrderDetailsByOrderId(wxOrder.getId());
                orderVO.setOrderDetails(wxOrderDetailsDTOS);
                orderVOS.add(orderVO);
            }
        }
        return orderVOS;
    }
}




